
<template>

  <div class="app-container">
    <div class="app-main">
      <div style="padding: 20px">
        <el-row>
          <el-col :span="12">
            <el-image style="width: 196px;" :src="zhiSrc"></el-image>
          </el-col>
          <el-col :span="12">
            <el-row :gutter="20">
              <el-col :span="6">
                <el-select v-model="selectValue" style="width: 100%">
                  <el-option
                      v-for="(item,index) in selectOptions"
                      :key="index"
                      :label="item"
                      :value="index"
                  />
                </el-select>
              </el-col>
              <el-col :span="6">
                <el-select v-model="areaValue" style="width: 100%" multiple collapse-tags>
                  <el-option
                      v-for="(item,index) in areaData"
                      :key="index"
                      :label="item"
                      :value="index"
                  />
                </el-select>
              </el-col>
              <el-col :span="6">
                <el-select v-model="companyValue" style="width: 100%" multiple collapse-tags>
                  <el-option
                      v-for="(item,index) in companyOptions"
                      :key="index"
                      :label="item"
                      :value="index"
                  />
                </el-select>
              </el-col>
              <el-col :span="3">
                <el-button style="width: 100%" type="primary" icon="Switch" @click="setTableData">对标</el-button>
              </el-col>
              <el-col :span="3">
                <el-button style="width: 100%" icon="Refresh" @click="reset">重置</el-button>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </div>
      <ul class="bench-ul">
        <li style="background-color: #f3f7fd">
          对标参数
        </li>
        <li style="background-color: #e6eeff" v-for="item in areaOptions">
          {{ item }}
        </li>
      </ul>
      <div style="height: 10px"></div>
      <ul class="bench-ul" v-for="item in tableData" style="margin-bottom: 10px">
        <li style="border: 1px solid #dde1ea;font-weight: normal">{{ item.name }}</li>
        <li v-for="val in item['values']" :style="{fontWeight:'normal',backgroundColor:getBgColor(val.value)}">
          {{ val.value }}
        </li>
      </ul>
    </div>
  </div>
</template>


<script setup>
import {detailsData} from '../data/data.js'
import {onMounted, reactive, ref} from "vue";
import utils from "@/utils/index.js";

const zhiSrc = utils.getAssetsFile('zhi.png')
const tableData = ref([])

const selectValue = ref(0)
const selectOptions = reactive(['关键基础件(气动)产业', '生命(医疗)健康产业'])

const areaData = ["奉化区", "海曙区", "江北区", "北仑区", "镇海区", "鄞州区", "象山县", "宁海县", "余姚市", "慈溪市"]
const areaOptions = ref([])
const areaValue = ref([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

const companyOptions = reactive(['平均注册资本(万元)', '企业数（家）', '近3年新增企业数（家）', '上市企业数（家）', '企业竞争力评分', '专利数量（条）', '专利授权率', '上市企业利润（亿元）', '上市企业R&D（亿元）'])
const companyValue = ref([0, 1, 2, 3, 4, 5, 6, 7, 8])

onMounted(() => {
  setTableData()
})

const setTableData = () => {
  areaValue.value.sort()
  areaOptions.value = areaValue.value.map(index => areaData[index])

  tableData.value = detailsData.reduce((acc, item) => {
    const filteredValues = item.values.filter((_, index) => areaValue.value.includes(index))
    if (filteredValues.length > 0) {
      acc.push({
        name: item.name,
        values: filteredValues
      })
    }
    return acc
  }, [])

  companyValue.value.sort()
  tableData.value = tableData.value.filter((_, index) => companyValue.value.includes(index))
}


const reset = () => {
  areaValue.value = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  companyValue.value = [0, 1, 2, 3, 4, 5, 6, 7, 8]
  setTableData()
}


const getBgColor = (value) => {
  if (value >= 0 && value < 200) {
    return '#e7eefe'
  } else if (value >= 200 && value < 400) {
    return '#bbd1fe'
  } else if (value >= 400) {
    return '#7ba5fc'
  } else {
    return '#e7eefe'
  }

}

</script>


<style scoped lang="scss">
.app-main {
  height: calc(100vh - 100px);
}

.bench-ul {
  padding: 0 20px;
  display: flex;
  align-items: center;

  > li {
    font-size: 16px;
    font-weight: bold;
    height: 55px;
    line-height: 55px;
    text-align: center;
  }

  > li:first-child {
    width: 300px;
  }

  > li:not(:first-child) {
    width: 148px;
    margin-right: 10px;
    margin-left: 10px;
  }

  > li:last-child {
    margin-right: 0;
  }
}

.bench-list {
  padding: 20px;
}
</style>
